package com.yanggu.spark.core.rdd.action

import org.apache.spark.{SparkConf, SparkContext}

//Action算子-CountByKey
//统计key的个数
object RDD35_CountByKey {

  def main(args: Array[String]): Unit = {

    //1. 创建sparkConf配置对象
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("spark")

    //2. 创建spark上下文对象
    val sparkContext = new SparkContext(sparkConf)

    //3. 从内存中创建RDD
    val value = sparkContext.makeRDD(List((1, "a"), (1, "a"), (1, "a"), (2, "b"), (3, "c"), (3, "c")))

    //4. countByKey
    //统计key出现的次数
    val map = value.countByKey()

    //5. 打印
    println(map)

    //6. 释放资源
    sparkContext.stop()
  }

}
